package com.jluzh10.learning.service.Impl;


import com.github.pagehelper.PageHelper;
import com.jluzh10.learning.dao.CourseClassifyMapper;
import com.jluzh10.learning.domain.CourseClassify;
import com.jluzh10.learning.domain.CourseClassifyExample;
import com.jluzh10.learning.service.CourseClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author yzg
 * @create 2019/5/24
 */
@Service
@Transactional
public class CourseClassifyServiceImpl implements CourseClassifyService {

    @Autowired
    private final CourseClassifyMapper classifyMapper;

    public CourseClassifyServiceImpl(CourseClassifyMapper classifyMapper) {
        this.classifyMapper = classifyMapper;
    }


    @Override
    public int addClassify(CourseClassify classify) {
        return classifyMapper.insertSelective(classify);
    }

    @Override
    public List<CourseClassify> findAll(Integer num) {
        CourseClassifyExample classifyExample=new CourseClassifyExample();
        classifyExample.setOrderByClause("sort desc");
        classifyExample.createCriteria().andStateEqualTo((byte) 1);
        if (num!=null&&num!=0){
            PageHelper.startPage(1,num);
        }
        return classifyMapper.selectByExample(classifyExample);
    }

    @Override
    public CourseClassify selectOneById(Integer classifyId) throws Exception {
        return classifyMapper.selectByPrimaryKey(classifyId);
    }
}
